package com.projectsexception.festivales.setup.xml;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.projectsexception.festivales.setup.FeedInfo;

public class FeedInfoHandler extends DefaultHandler {
    
    private List<FeedInfo> feeds;
    private FeedInfo tmpFeedInfo;

    @Override
    public void startDocument() {
        feeds = new ArrayList<FeedInfo>();
    }
    
    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        String s = SAXHandlerUtil.getElementName(localName, qName);
        if (s.equals("feed")) {
            tmpFeedInfo = new FeedInfo();
            tmpFeedInfo.setName(attributes.getValue("name"));
            tmpFeedInfo.setLink(attributes.getValue("link"));
        }
    }
    
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        String s = SAXHandlerUtil.getElementName(localName, qName);
        if ("feed".equals(s)) {
            feeds.add(tmpFeedInfo);
        }
    }

    public List<FeedInfo> getResult() {
        return feeds;
    }

}
